package com.yzh;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;

import java.io.*;

/**
 * @author 于振晗
 * @title: DouYinDown
 * @description: TODO
 * @date 2022年11月11日
 * @path com.yzh
 */
public class DouYinDown {
    public static void main(String[] args) throws IOException {
        // 视频地址
        String url = "https://v26-web.douyinvod.com/159cef50d988153b4c0d8e5744ffeb21/636e7d37/video/tos/cn/tos-cn-ve-15c001-alinc2/63f7672828334cb2a161b88a9f06cdbc/?a=6383&ch=26&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C3&cv=1&br=2280&bt=2280&cs=0&ds=3&ft=LjhJEL998xztuo0mo0P58lZW_3iXvmw-OVJE70It0bPD-Ani&mime_type=video_mp4&qs=0&rc=aDdpZjk1aGVlaDs6OjhoM0BpajhxZTw6ZjQ8PDMzNGkzM0BjNC1gMV5hNV8xYzNhLzZfYSNjY2kxcjRvamFgLS1kLWFzcw%3D%3D&l=202211112348580101511981953B31379E";

        // 请求视频地址，转存视频到本地
        HttpRequest httpRequest = HttpRequest.get(url);
        HttpResponse execute = httpRequest.execute();
        InputStream inputStream = execute.bodyStream();

        File file = new File("C:\\Users\\Xiaojiuc\\Desktop\\douyin\\test.mp4");
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        int index;
        byte[] bytes = new byte[1024];

        while ((index = inputStream.read(bytes)) != -1){
            fileOutputStream.write(bytes);
        }
        fileOutputStream.flush();
        fileOutputStream.close();
    }
}
